package com.qiguliuxing.dts.job.base;

import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.dangdang.ddframe.job.config.JobCoreConfiguration;
import com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration;
import com.dangdang.ddframe.job.lite.config.LiteJobConfiguration;

/**
 * 基础 lite job 定义
 * @author qiguliuxing
 * @since 1.0.0
 */
public class LiteJobDefinition {

    public static LiteJobConfiguration getLiteJobConfiguration(final Class<? extends SimpleJob> jobClass, final String cron,
                                                               final int shardingTotalCount, final String shardingItemParameters, final String jobParameters) {

        // 定义作业核心配置
        JobCoreConfiguration simpleCoreConfig = JobCoreConfiguration
                .newBuilder(jobClass.getName(), cron, shardingTotalCount).shardingItemParameters(shardingItemParameters)
                .jobParameter(jobParameters).build();

        // 定义SIMPLE类型配置
        SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(simpleCoreConfig,
                jobClass.getCanonicalName());

        // 定义LITE作业根配置
        LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration.newBuilder(simpleJobConfig).overwrite(true)
                .build();
        return simpleJobRootConfig;
    }
}
